﻿import com.dinmax.flash.common.collection.*;

class com.dinmax.flash.utilities.classes.ClassFinder {

	public static function create(package:String) : Function {
		trace("ClassFinder.as | create= "+package);
		var myClass:Function = Function(eval(package));
		trace("class= "+myClass);
		return new myClass();
	};

	public static function getGetters(objectClass:Object):Array {
		var a:Array=new Array();
		var t:Function = Function(objectClass.__proto__);
		_global.ASSetPropFlags(t,null,6,true);
		for(var sNested in t){
			if(sNested.indexOf("get")==0){
				a.push(sNested);
			}
		}	
		return a;
	};
	
	public static function getAttributes(objectClass:Object):Collection {
		var attributes:Collection = new Collection();
		var getters:Array = ClassFinder.getGetters(objectClass);
		for(var i:Number = 0; i < getters.length; i++){
			var sName:String = (getters[i].substr(3));
			var sKey:String = sName.substr(0, 1).toLowerCase();
			sKey += sName.slice(1, sName.length);
			var sValue:String = ClassFinder.applyMethod(objectClass, getters[i]).toString();
			attributes.addItem(sKey, sValue);
		}
		return attributes;
	};
	
	public static function applyMethod(object:Object, method:String, parameters:Array): Object  {
		//trace("ClassFinder.as | apply()");
		return object[method].apply(object, parameters);
	}; //fin funci	

}; // fin de clase